import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_base/page/splash_page.dart';
import 'package:flutter_base/provider/count_provider.dart';
import 'package:flutter_base/resource/strings/resource_string.dart';
import 'package:flutter_base/resource/theme/dark_mode_provider.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/screenutil_init.dart';
import 'package:provider/provider.dart';

import 'base/base_container.dart';

void main() {
  runApp(MyApp(SplashPage()));
  SystemUiOverlayStyle systemUiOverlayStyle =
      SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}

// ignore: must_be_immutable
class MyApp extends StatelessWidget {
  Widget child;

  MyApp(this.child); // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp, //只能纵向
    ]);
    //初始化适配
    return ScreenUtilInit(
        designSize: Size(375, 812),
        allowFontScaling: false,
        builder: () => MultiProvider(
              providers: [
                ChangeNotifierProvider.value(value: DarkModeProvider()),
                ChangeNotifierProvider.value(value: CountProvider()),
              ],
              child: Consumer<DarkModeProvider>(
                  builder: (context, darkModeProvider, _) {
                return MaterialApp(
                  theme: new ThemeData(
                      primarySwatch: Colors.blue,
                      highlightColor: Colors.transparent,
                      splashColor: Colors.transparent,
                      platform: TargetPlatform.iOS //添加这个属性即可
                      ),
                  localizationsDelegates: [
                    const DemoLocalizationsDelegate(),
                    GlobalMaterialLocalizations.delegate,
                    GlobalWidgetsLocalizations.delegate,
                  ],
                  supportedLocales: [
                    const Locale('en', ''),
                    const Locale('zh', ''),
                  ],
                  home: child,
                );
              }),
            ));
  }
}
